It is very difficult to answer your question without knowing details of the application but by a quick check of the respective parameters on the datasheets I would say that you could replace the IRF540 with an IRF640 but you could not replace an IRF510 with an IRF640.
But you could try replacing an IRF510 with an IRF640. It will do no harm and, depending on the circuit, may well work.
The gate threshold voltage at 4V is the same for all three NMOSFETs, so the DC conditions will not be affected.