Upon a conviction of any crime mentioned in sections seven, eight, seventeen, eighteen, twenty or twenty-eight or upon forfeiture by persons prosecuted for any such crime of any recognizance for their appearance to answer to the same, the superior court may order compensation to the prosecutor and to the officer who has secured and kept the evidence of the crime, not exceeding their actual expenses, with a reasonable allowance for their time and trouble, which shall be paid by the county.
Mass. Gen. Laws ch. 267, § 31