Quantum localization through interference on homoclinic and heteroclinic circuits