US President Donald Trump has warned Tesla CEO Elon Musk of "serious consequences" if he gives funding to Democratic candidates.