Why does this function crash a MEGA 2560?

Don't get rid of "static". I put it there for a reason. Without it you are returning the address of a variable on the stack, which no longer exists.