When any person shall be brought before a court or other committing magistrate of any county, city or town in this state, having jurisdiction of the alleged offense, charged with the commission of a crime or misdemeanor, and such complaint upon examination shall appear to be unfounded, no costs shall be payable by such acquitted party, but the same shall be chargeable to the county, city or town for or in which the said complaint is triable, but if the court or other magistrate trying said charge, shall decide the complaint was frivolous or malicious, the judgment or verdict shall also designate who is the complainant, and may adjudge that said complainant pay the costs. In such cases a judgment shall thereupon be entered for the costs against said complainant, who shall stand committed until such costs be paid or discharged by due process of law.