If you were to have ants in your pants you would be trying to get them out of your pants, right? Who wants ants crawling all on their legs?
When someone tries to get ants off their legs they are likely to be very uncomfortable and wiggly (aka moving around a lot).
When you say someone has ants in their pants it means that figuratively ants are in their pants and that they are acting very uncomfortable and fidgety
Hope this helped!
~Just a girl in love with Shawn Mendes