Place onions and garlic into a large saucepan, add water to cover. Place over high heat and bring to the boil, reduce heat to medium-low, cover, and simmer for 45 minutes. Add the ginger, and continue simmering for 5 more minutes.
Puree the onion in a food processor or blender in batches until smooth. Place a large saucepan over medium-high heat, pour in the tomatoes, and season with turmeric, cumin, garam masala, curry paste and red chilli flakes. Bring to a simmer, then pour in the onion puree. Simmer for 45 minutes.