When a person charged with a felony is supposed by the magistrate before whom the person is brought to have possession of a dangerous weapon, or anything which may be used as evidence of the commission of the offense, the magistrate may direct the person to be searched in the magistrate's presence, and the weapon or other thing to be retained, subject to the magistrate's order or the order of the court in which the defendant may be tried.
N.D.C.C. § 29-29-20