Don't trust Proteus! If it works on real hardware but not in the simulator that usually indicates the simulated device isn't accurate, i.e. in this case the timers and CCP peripherals don't work the same as in the real chip.
The timer 1 handling is deeply suspect in your sample code. Zeroing it after a successful period measurement then waiting 500ms is asking for trouble. *IF* the timer needs zeroing it should be immediately before the wait for the first capture.
Also checking if the first capture is less than the second one is dumb, and may well be the root cause of the code failing under certain circumstances. It can only be less if there's been a timer rollover between the two captures. If so, the difference will still be valid if its less than one timer rollover period and you use 16 bit unsigned maths (i.e. modulo 655336).
It gets more complex if you need to extend the capture width in software using the overflow interrupt flag, as you need to handle the case of rollover very near the moment of capture, and determine which came first.