Hi Barbolani,
the script chops the route in small segments, but this is horizontal segmentation, not 3D segmentation. So, if you are 1500m high and you are 2500m away in 2D then you are already almost 3000m away of the destination at ground level. Do you experience the same problem with the plane flying at 500m AGL? If not, then might be you will need to readjust the ranges increasing them a bit.