Getting correct coordinate

I am implementing the line draw function on my terrain engine using gluUnproject to get the coordinates of mouse position.
Values I am getting is almost correct, but z coordinates are always a little small, which causes most lines to go under the terrain.

I am guessing it comes from z buffer precision.
Is there anyway to avoid this.