Section 131. The board of aldermen of a city or the selectmen of a town, if a public way, and the department of highways, if a state highway, may authorize structures or alterations within, or partly within, the limits thereof, which are necessary for carrying a street railway over or under a railroad, if such way is not thereby made unsafe for other public travel.