When a person is brought before a magistrate upon a charge of any offence mentioned in sections fifty-three, sixty-six and sixty-eight, such magistrate, or the court before which the case may be carried on appeal, may at any stage of the proceedings direct the defendant or appellant to be discharged, upon his entering into a recognizance, with sufficient sureties, in such sum as the magistrate or court orders, for his good behavior for not less than six months nor more than two years, and paying the expenses of prosecution or such part thereof as the magistrate or court orders.
Mass. Gen. Laws ch. 272, § 57