from typing import OrderedDict


def filter_words(word_to_idx, vectors, vocabulary):
    """Filter word vector data to vocabulary."""
    filtered_to_idx, filtered_indices = OrderedDict(), []
    for word, idx in word_to_idx.items():
        if word in vocabulary:
            filtered_to_idx[word] = len(filtered_to_idx)
            filtered_indices.append(idx)
    return filtered_to_idx, vectors[filtered_indices]