Yes...refs screwed up the call.
However...
1) I'm not even sure Staley should have been flagged
2) Matthews threw 2 punches. He probably should have been ejected
3) After Matthews hit Kaep later in the game, he pretty clearly taunted him and should have been flagged which would have given Niners a 1st and goal.
4) There is no guarantee that they would have kicked a FG.
5) This was a second qtr play...not something at the end of the game. Different decisions would have been made on both sides of the ball.
So, while it was a bad call, it was hardly the only reason the 49ers won.