We present a robust method, weighted von Mises kernel density estimation, along with boundary correction to reconstruct the underlying number density field of galaxies. We apply this method to galaxies brighter than $rm HST/F160wle 26$ AB mag at the redshift range of $0.4leq z leq 5$ in the five CANDELS fields (GOODS-N, GOODS-S, EGS, UDS, and COSMOS). We then use these measurements to explore the environmental dependence of the star formation activity of galaxies. We find strong evidence of environmental quenching for massive galaxies ($rm M gtrsim 10^{11} rm {M}_odot$) out to $zsim 3.5$ such that an over-dense environment hosts $gtrsim 20%$ more massive quiescent galaxies compared to an under-dense region. We also find that environmental quenching efficiency grows with stellar mass and reaches $sim 60%$ for massive galaxies at $zsim 0.5$. The environmental quenching is also more efficient in comparison to the stellar mass quenching for low mass galaxies ($rm M lesssim 10^{10} rm {M}_odot$) at low and intermediate redshifts ($zlesssim 1.2$). Our findings concur thoroughly with the over-consumption quenching model where the termination of cool gas accretion (cosmological starvation) happens in an over-dense environment and the galaxy starts to consume its remaining gas reservoir in depletion time. The depletion time depends on the stellar mass and could explain the evolution of environmental quenching efficiency with the stellar mass.