Derivation of the wavefunction collapse in the context of Nelson's stochastic mechanics