Repeat this 100 times until it really sinks in: All poker hands have exactly 5 cards, no more, no fewer. EXACTLY 5 cards. In Hold'em, you play the best possible 5-card hand you can make out of the 7 available to you, and your 5 cards are compared against your opponent's 5 cards. Exactly 5 cards, no more, no fewer.
If two players both have two pair, the winner is determined by comparing (1) the higher pair, (2) the lower pair, and (3) the fifth card in the hand.
So, for example (ignoring suits for now)
Board: Ax 2x Jx 4x 9x
Player 1: Ax 2x
Player 2: Jx 9x
Player 1 has AA229, which beats JJ99A, because aces beat jacks and there's no need to go further.
Board: Kx 9x 8x Jx 4x
Plr 1: Kx8x
Plr 2: KxJx
Player 1's KK88J loses to player 2's KKJJ9, because jacks beat eights. No need to go to the fifth card.
Board: Ax 5x Ax Qx 3x
Plr 1: Qx Jx
Plr 2: Qx 4x
Plr 1 has AAQQJ, which beats Plr 2's AAQQ5 (since the 5 on the board beats that player's 4, he plays it, but still loses to the J).
Board: Ax 5x 5x Qx 3x
Plr 1: Ax2x
Plr 2: Ax9x
In this case, even though plr 2's second card is higher, they tie, because each is playing AA55Q--the Q on the board is the same for both.
Board: Ax 5x Jx 7x 7x
Plr 1: Ax5x
Plr 2: AxKx
Here, player 1's extra pair of 5s is useless: his best 5-card hand is AA77J, which loses to player 2's AA77K.
Board: Ax 9x Qx Qx Ax
Plr 1: 8x8x
Plr 2: 4x4x
These players also tie, because the best 5-card hand is AAQQ9. The poket pairs simply don't matter. On the other hand:
Board Ax 3x Qx Qx Ax
Plr 1: 8x8x
Plr 2: 4x4x
Now player 1 has AAQQ8, and beats player 2's AAQQ4.