private void searchLevel(Node node, double[] query, ResultSet resultSet,
			int k, float eps, Double mindistsq, ArrayList<Double> dists) {
		// If this is a leaf node.
		if (node.child1 == null && node.child2 == null) {
			double worstDistance = resultSet.worstDistance();
			for (int i = node.leftObjectIndex; i < node.rightObjectIndex; i++) {
				double dist = metric.distance(query,
						data[objectsIndices.get(i)]);
				if (dist < worstDistance) {
					resultSet.addPoint(dist, objectsIndices.get(i));
				}
			}
			return;
		}

		// Which child branch should be taken first?
		int cutDimension = node.cutDimension;
		double queryValueInCutDimension = query[cutDimension];
		double diff1 = queryValueInCutDimension - node.cutDimensionLow;
		double diff2 = queryValueInCutDimension - node.cutDimensionHigh;
		Node bestChild, otherChild;
		double cutDistance;
		if (diff1 + diff2 < 0) {
			bestChild = node.child1;
			otherChild = node.child2;
			cutDistance = metric.distance(queryValueInCutDimension,
					node.cutDimensionHigh);
		} else {
			bestChild = node.child2;
			otherChild = node.child1;
			cutDistance = metric.distance(queryValueInCutDimension,
					node.cutDimensionLow);
		}

		// Call recursively to search next level down.
		searchLevel(bestChild, query, resultSet, k, eps, mindistsq, dists);
		double dst = dists.get(cutDimension);
		mindistsq = mindistsq - dst + cutDistance;
		dists.set(cutDimension, cutDistance);
		if (mindistsq * eps <= resultSet.worstDistance()) {
			searchLevel(otherChild, query, resultSet, k, eps, mindistsq, dists);
		}
		dists.set(cutDimension, dst);
	}