Section 44A. Motor vehicles registered under the law of this commonwealth and not exempt from execution under clause Sixteenth of section thirty-four of chapter two hundred and thirty-five shall not be attached by writ of attachment in a civil action based upon a contract unless written consent to such attachment is endorsed on the writ and signed by a justice, associate justice or special justice of the court wherein such action is commenced. Costs in any action in which such a motor vehicle has been attached shall be in the discretion of the court.