An accurate and robust sperm cells tracking algorithm that is able to detect and track sperm cells in videos with high accuracy and efficiency is presented. It is fast enough to process approximately 30 frames per second. It can find the correct path and measure motility parameters for each sperm. It can also adapt with different types of images coming from different cameras and bad recording conditions. Specifically, a new way is offered to optimize uneven lighting images to improve sperm cells detection which gives us the ability to get more accurate tracking results. The shape of each detected object is used to specify collided sperms and utilized dynamic gates which become bigger and smaller according to the sperm cell's speed. For assigning tracks to the detected sperm cells positions an improved version of branch and bound algorithm which is faster than the normal one is offered. This sperm cells tracking algorithm outperforms many of the previous algorithms as it has lower error rate in both sperm detection and tracking. It is compared with six other algorithms, and it gives lower tracking error rates. This method will allow doctors and researchers to obtain sperm motility data instantly and accurately.