The question of whether to go for Masterpiece or Gold will obviously depend on the board, but here's a first approximation using a simple test: which gives your deck a better average card value? Remember that Province games need to hit $1.6/card and $5 rushes or slogs need $1/card.
From crunching the numbers, I have a couple of general observations. First, bigger decks prefer Masterpiece+overpay, since the impact of adding additional cards is smaller. Second, decks with a low total coin value prefer Masterpiece as well, since each additional Silver adds to the deck's coin total.
The threshold depends on both of these things. The actual math is not the kind of stuff you'd want to use in a real game, but we'll build an approximation from it. The formula: If 3*money in deck (prior to purchase) + 5 < 4*cards in deck (prior to purchase), buy Masterpiece.
The more realistic version: when the money:card ratio exceeds 5:4, prefer Gold. So, a 12 card deck with 15 or more coin should lean Gold, less than 15, Masterpiece.