There is a chicken and egg problem here that most posters have ignored thus far....
If your knees open before the hips (which is clearly your biggest fault, bravo on picking that out), then the problem may be a muscle imbalance as been previously diagnosed, and suitable treatments have already been listed here.
The chicken and egg problem comes in because there is an assumption that the reason for your hips opening first is a muscle imbalance, whereas the muscle imbalance may have been caused by you learning the movement in a faulty way. The bad form has become ingrained, and now your muscles are imbalanced, which makes the problem even worse.
Either way, you have a problem where your muscles are being imbalanced, and it is causing improper form, which is causing muscles to become more imbalanced....and so on. To rectify this, one half of it is the treatment/prevention tips mentioned above by previous posters, but also focus on proper cueing to fix the movement. You can get your muscles all balanced and strong and still perform the movement incorrectly because your body THINKS it's doing it right.
I would suggest a "pull back" cue for your arms to keep them straight and tight against the body, with the bar rubbing along the shins. I would also suggest a "lean back" cue for your ass, as when you are focused on leaning back, the hips should be set back further, keeping the knees more parallel and forcing them to open later. Of course, you won't really be leaning back very much, but the visualization/cue in your head should help.
You may want to try and identify other cues that can help aside from just increasing strength in weak muscles.