A Framework for Uncertainty Quantification Based on Nearest Neighbors Across Layers