Higher-order Melnikov analysis of homo/heteroclinic bifurcations in mechanical oscillators